package edu.njust.cma.mapper;

import edu.njust.cma.DTO.SubTaskForLab;
import edu.njust.cma.pojo.SubtaskStaff;
import edu.njust.cma.pojo.Task;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

@Mapper
public interface
SubtaskStaffMapper {

    @Select("select * from subtasks_staff where task_id=#{taskId}")
    List<SubtaskStaff> getStaffTask(Integer taskId);


    @Insert("insert into subtasks_staff (task_id,staff_id, user_id) " +
            "values (#{taskId},#{staffId},#{userId})")
    void insert(SubtaskStaff subtaskStaff);

    @Update("update subtasks_staff set status=#{status} where task_id=#{taskId}")
    void updateStatusByTaskId(Integer taskId, int status);


    @Select("select status from subtasks_staff where task_id=#{taskId}")
    List<Integer> getStatusByTaskId(Integer taskId);


    @Select("select * from subtasks_staff where user_id=#{userId}")
    List<SubtaskStaff> getStaffTaskByUserId(int userId);


    @Update("update subtasks_staff set resume_pdf_url=#{resumePdfUrl}, training_pdf_url = #{trainingPdfUrl}," +
            "assessment_pdf_url=#{assessmentPdfUrl},authorization_pdf_url=#{authorizationPdfUrl},submission_time = #{submissionTime}" +
            " where id=#{id}")
    void updateUrlAndTime(SubtaskStaff subtaskStaff);

    @Select("select * from subtasks_staff where task_id=#{taskId} and staff_id=#{staffId}")
    SubtaskStaff getSubtaskStaffByTaskIdAndStaffId(int taskId, Integer staffId);
}
